package com.nameli.admin.config.aop;

import com.nameli.SIM.util.PropertiesUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
import redis.clients.jedis.Jedis;


/**
 * @author NAME-L
 * @Description AOP监控redis连接
 * @className PageParamCheck
 * @date 2021-11-03 16:30:05
 */
@Aspect
@Component
public class PageParamCheck {
    private static final Log log = LogFactory.getLog(PageParamCheck.class);
    private static final String URL = PropertiesUtil.getProperty("application" , "spring.redis.host");
    private static final String PORT = PropertiesUtil.getProperty("application" , "spring.redis.port");

    @Pointcut("execution( public * com.nameli.admin.service.impl.*.update*(..)) || execution( public * com.nameli.admin.service.impl.*.insert*(..)) ")
    public void redisCheck() {
    }

    @Before("redisCheck()")
    public void beforeCheck(){
        try {//连接本地Redis服务
            Jedis jedis = new Jedis(URL , Integer.parseInt(PORT));
            String ping = jedis.ping();
            if ("PONG".equalsIgnoreCase(ping)) {
                log.info("redis缓存有效！" + ping);
            }
        } catch (Exception e) {
            log.info("redis缓存失败！");
            throw e;
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
    }
}
